//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_createarmor.sqf"
#include "x_setup.sqf"

private ["_numvehicles", "_radius", "_pos", "_nr", "_nrg", "_typenr", "_i", "_newgroup", "_reta", "_pos_center", "_do_patrol", "_ret_grps"];
_pos_center = _this select 6;
_numvehicles = _this select 7;
_radius = _this select 8;
_do_patrol = if (_radius < 50) then {false} else {if (count _this == 10) then {_this select 9} else {false}};
_ret_grps = [];
_pos = [];

for "_nr" from 0 to 2 do {
	_nrg = _this select (1 + (_nr * 2));
	if (_nrg > 0) then {
		if (GVAR(MissionType) == 2) then {_nrg = _nrg + 2};
		_typenr = _this select (_nr * 2);
		for "_i" from 1 to _nrg do {
			_newgroup = [GVAR(side_enemy)] call FUNC(creategroup);
			if (_radius > 0) then {
				_pos = [_pos_center, _radius] call FUNC(GetRanPointCircle);
				if (count _pos == 0) then {
					for "_ee" from 0 to 99 do {_pos = [_pos_center, _radius] call FUNC(GetRanPointCircle);if (count _pos > 0) exitWith {}};
				};
			} else {
				_pos = _pos_center;
			};
			_unit_array = [_typenr, GVAR(enemy_side)] call FUNC(getunitliste);
			_reta = [_numvehicles, _pos, _unit_array select 1, _newgroup, 0,-1.111] call FUNC(makevgroup);
			{_x setVariable [QGVAR(smvec), true]} forEach (_reta select 0);
			GVAR(x_sm_vec_rem_ar) = [GVAR(x_sm_vec_rem_ar), _reta select 0] call FUNC(arrayPushStack2);
			GVAR(x_sm_rem_ar) = [GVAR(x_sm_rem_ar), _reta select 1] call FUNC(arrayPushStack2);
			_newgroup allowFleeing 0;
			if (!_do_patrol) then {
				_newgroup setCombatMode "YELLOW";
				_newgroup setFormation (["COLUMN","STAG COLUMN","WEDGE","ECH LEFT","ECH RIGHT","VEE","LINE","DIAMOND"] call FUNC(RandomArrayVal));
				_newgroup setFormDir (floor random 360);
				_newgroup setSpeedMode "NORMAL";
			};
			_ret_grps set [count _ret_grps, _newgroup];
			if (_do_patrol) then {
				[_newgroup, _pos, [_pos_center, _radius], [5, 15, 30]] spawn FUNC(MakePatrolWPX)
			};
		};
	};
};
_ret_grps